﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SerializedData
{
    /// <summary>
    /// Represents a Scene.
    /// </summary>
    [Serializable()]
    public class SScene
    {
        private long mId;
        private String mName;
        private String mDescription;
        private String mTts;
        private bool mChecked;
        private List<long> mCommands = new List<long>();

        public SScene(long id,String name, String description, String tts)
        {
            mId = id;
            mName = name;
            mDescription = description;
            mTts = tts;
        }

        public long getId()
        {
            return mId;
        }

        public void addCommand(SCommand command)
        {
            if(!mCommands.Contains(command.getId()))
                mCommands.Add(command.getId());
        }
        public void addCommandById(String id)
        {
            if (!containsCommandWithId(id))
                mCommands.Add(long.Parse(id));

        }
        public void removeAllCommands()
        {
            mCommands = null;
            mCommands = new List<long>();
        }

        public List<SCommand> getCommands()
        {
            DataCollection dc = DataCollection.Instance;
            List<SCommand> retCommands = new List<SCommand>();
            List<long> tbd = new List<long>();

            foreach (long id in mCommands)
            {
                SCommand sCommand = dc.getCommandPool().Find(o => o.getId().Equals(id));
                if (sCommand == null)
                    tbd.Add(id);
                else
                    retCommands.Add(sCommand);
            }
            foreach (long id in tbd)
                if (mCommands.Contains(id))
                    mCommands.Remove(id);
            return retCommands;
        }
        public bool containsCommandWithId(String id)
        {
            foreach (long item in mCommands)
                if (("" + item).Equals(id))
                    return true;
            return false;
        }

        public void setName(String name)
        {
            mName=name;
        }

        public void setDescription(String description)
        {
            mDescription=description;
        }

        public void setTts(String tts)
        {
            mTts=tts;
        }

        public String getName()
        {
            return mName;
        }

        public String getDescription()
        {
            return mDescription;
        }

        public String getTts()
        {
            return mTts;
        }

        public bool isEmpty()
        {
            return (mCommands.Count < 1);
        }

    }
}
